// 用户相关类型定义
import type { BaseEntity, Permission, FileInfo } from './index'

// 用户角色枚举
export enum UserRole {
  ADMIN = 'admin',
  MODERATOR = 'moderator',
  USER = 'user',
  GUEST = 'guest',
  TEACHER = 'teacher',
  STUDENT = 'student'
}

// 用户状态枚举
export enum UserStatus {
  ACTIVE = 'active',
  INACTIVE = 'inactive',
  PENDING = 'pending',
  BANNED = 'banned',
  DELETED = 'deleted'
}

// 用户性别枚举
export enum UserGender {
  MALE = 'male',
  FEMALE = 'female',
  OTHER = 'other'
}

// 用户基本信息接口
export interface User extends BaseEntity {
  id: number | string
  username: string
  password?: string
  nickname?: string
  avatar?: string
  email: string
  phone?: string
  role: UserRole | string
  status: UserStatus | string
  gender?: UserGender | string
  birthday?: string
  bio?: string
  website?: string
  location?: string
  lastLogin?: string
  registerIp?: string
  lastIp?: string
  userAgent?: string
  preferences?: Record<string, any>
  settings?: Record<string, any>
  roles?: string[] // 兼容性字段
  createdAt: string
  updatedAt: string
  permissions?: Permission[]
  profileViews?: number
  followers?: number
  following?: number
  posts?: number
  comments?: number
  favorites?: number
  notifications?: number
  isOnline?: boolean
  isVerified?: boolean
  verificationToken?: string
  resetToken?: string
  resetTokenExpire?: string
}

// 用户注册接口
export interface RegisterUser {
  username: string
  password: string
  email: string
  nickname?: string
  phone?: string
  agreeTerms: boolean
}

// 用户登录接口
export interface LoginUser {
  username: string
  password: string
  rememberMe?: boolean
  captcha?: string
  captchaKey?: string
}

// 用户登录响应接口
export interface LoginResponse {
  token: string
  refreshToken: string
  expiresIn: number
  user: User
}

// 用户资料接口
export interface UserProfile {
  id?: number
  username?: string
  nickname?: string
  avatar?: string
  bio?: string
  website?: string
  location?: string
  gender?: UserGender | string
  birthday?: string
  email?: string
  phone?: string
  role?: string
  status?: string
  isEnabled?: boolean
  isLocked?: boolean
  lastLogin?: string
  createdAt?: string
  updatedAt?: string
}

// 用户安全设置接口
export interface UserSecurity {
  oldPassword?: string
  newPassword?: string
  confirmPassword?: string
  email?: string
  phone?: string
  twoFactorEnabled?: boolean
  twoFactorCode?: string
}

// 用户偏好设置接口
export interface UserPreferences {
  language?: string
  timezone?: string
  theme?: 'light' | 'dark' | 'system'
  notifications?: {
    email?: boolean
    push?: boolean
    sms?: boolean
  }
  privacy?: {
    profileVisible?: boolean
    lastSeenVisible?: boolean
    emailVisible?: boolean
    phoneVisible?: boolean
  }
  interface?: {
    sidebarCollapsed?: boolean
    fontSize?: number
    layout?: string
  }
  [key: string]: any
}

// 用户统计信息接口
export interface UserStats {
  posts: number
  comments: number
  likes: number
  followers: number
  following: number
  favorites: number
  views: number
  onlineTime: number
  completedTasks: number
  badges: number
}

// 用户成就接口
export interface UserAchievement {
  id: string | number
  userId: string | number
  name: string
  description: string
  icon: string
  level: number
  progress: number
  completed: boolean
  completedAt?: string
  createdAt: string
}

// 用户徽章接口
export interface UserBadge {
  id: string | number
  name: string
  description: string
  icon: string
  color: string
  level: number
  obtainedAt: string
}

// 用户关注接口
export interface UserFollow {
  id: string | number
  followerId: string | number
  followingId: string | number
  createdAt: string
  follower?: User
  following?: User
}

// 用户消息接口
export interface UserMessage {
  id: string | number
  senderId: string | number
  receiverId: string | number
  content: string
  isRead: boolean
  createdAt: string
  readAt?: string
  sender?: User
  receiver?: User
}

// 用户通知接口
export interface UserNotification {
  id: string | number
  userId: string | number
  title: string
  content: string
  type: string
  isRead: boolean
  createdAt: string
  readAt?: string
  relatedId?: string | number
  relatedType?: string
}

// 用户课程接口
export interface UserCourse {
  id: string | number
  userId: string | number
  courseId: string | number
  progress: number
  lastStudyAt?: string
  completed: boolean
  completedAt?: string
  createdAt: string
  updatedAt: string
}

// 用户作业接口
export interface UserAssignment {
  id: string | number
  userId: string | number
  assignmentId: string | number
  submission?: string
  file?: FileInfo
  score?: number
  feedback?: string
  status: string
  submittedAt?: string
  gradedAt?: string
  createdAt: string
  updatedAt: string
}

// 用户收藏夹接口
export interface UserCollection {
  id: string | number
  userId: string | number
  name: string
  description?: string
  cover?: string
  items: number
  createdAt: string
  updatedAt: string
}

// 用户活动日志接口
export interface UserActivity {
  id: string | number
  userId: string | number
  action: string
  module: string
  entityId?: string | number
  entityType?: string
  details?: string
  ip: string
  userAgent: string
  createdAt: string
}

// 用户学习记录接口
export interface UserLearningRecord {
  id: string | number
  userId: string | number
  resourceId: string | number
  resourceType: string
  progress: number
  duration: number
  lastStudyAt?: string
  completed: boolean
  completedAt?: string
  createdAt: string
  updatedAt: string
}

// 用户评分接口
export interface UserRating {
  id: string | number
  userId: string | number
  entityId: string | number
  entityType: string
  score: number
  comment?: string
  createdAt: string
  updatedAt: string
}

// 用户认证接口
export interface UserAuth {
  id: string | number
  userId: string | number
  provider: string
  providerId: string
  accessToken?: string
  refreshToken?: string
  expiresAt?: string
  createdAt: string
  updatedAt: string
}

// 用户黑名单接口
export interface UserBlacklist {
  id: string | number
  userId: string | number
  blockedUserId: string | number
  reason?: string
  createdAt: string
  blockedUser?: User
}